<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str = "www.baidu.com?name=ligang&age=12&sex";
        let pramary = /(.+)\?(.+)$/.exec(str)[2];
        let arr = pramary.split("&");
        let arrObj = {};
        arr.forEach(ar => {
            if(/=/.test(ar)){
                let [key, value] = ar.split("=");
                value = /^(\d+)$/.test(value) ? parseInt(value) : value;
                if(arrObj.hasOwnProperty(key)){
                    arrObj[key] = [].concat(arrObj[key], value);
                }else{
                    arrObj[key] = value;
                }

            }else{
                arrObj[ar] = true;
            }
        })
        console.log(arrObj);
    </script>
</body>
</html>